package com.oneandone.mamba.mc.model;

import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.OneToMany;

@Entity
public class Account extends BaseEntity {

	@Column(name = "iban_code")
	private String ibanCode;

	@Column(name = "money_available")
	private Long totalMoneyAvailable;

	@OneToMany
	private Client client;
	private Set<Transaction> transactions;
	private Status status;

	public static enum Status {
		INACTIVE, ACTIVE, SUSPENDED, LOCKED;
	}

	public String getIbanCode() {
		return this.ibanCode;
	}

	public void setIbanCode(String ibanCode) {
		this.ibanCode = ibanCode;
	}

	public Long getTotalMoneyAvailable() {
		return this.totalMoneyAvailable;
	}

	public void setTotalMoneyAvailable(Long totalMoneyAvailable) {
		this.totalMoneyAvailable = totalMoneyAvailable;
	}

	public Client getClient() {
		return this.client;
	}

	public void setClient(Client client) {
		this.client = client;
	}

	public Set<Transaction> getTransactions() {
		return this.transactions;
	}

	public void setTransactions(Set<Transaction> transactions) {
		this.transactions = transactions;
	}

	public Status getStatus() {
		return this.status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	// Business logic
	private void checkAccount() {
		if (this.status != Status.ACTIVE) {
			throw new RuntimeException("Other error");
		}
	}

	public void withdraw(double amount) {
		this.checkAccount();

		// todo
	}

	public void deposit(double amount) {
		this.checkAccount();
	}
}
